package pl.cezary.butler.walili.client.config;

import pl.cezary.butler.walili.common.config.Configuration;

/**
 *
 * @author Czarek
 */
public class ClientConfiguration extends Configuration {

    private static ClientConfiguration INSTANCE = new ClientConfiguration();
    private volatile Integer clientWorkingThreads;
    private volatile Integer clientTaskQueueLength;
    private volatile Integer clientFetchDelay;
    private volatile Integer differentServerPriorityHandicap;

    public static ClientConfiguration getInstance() {
        return INSTANCE;
    }

    @Override
    protected void clearFetched() {
        super.clearFetched();
        clientFetchDelay = null;
        clientTaskQueueLength = null;
        clientWorkingThreads = null;
        differentServerPriorityHandicap = null;
    }

    public Integer getDifferentServerPriorityHandicap() {
        if (differentServerPriorityHandicap == null) {
            differentServerPriorityHandicap = Integer.valueOf(prop.getProperty("different_server_priority_handicap"));
        }
        assert (differentServerPriorityHandicap != null);
        return differentServerPriorityHandicap;
    }

    public Integer getClientWorkingThreads() {
        if (clientWorkingThreads == null) {
            clientWorkingThreads = Integer.valueOf(prop.getProperty("client_working_threads"));
        }
        assert (clientWorkingThreads != null);
        return clientWorkingThreads;
    }

    public Integer getClientTasksQueueLength() {
        if (clientTaskQueueLength == null) {
            clientTaskQueueLength = Integer.valueOf(prop.getProperty("client_tasks_queue_len"));
        }
        assert (clientTaskQueueLength != null);
        return clientTaskQueueLength;
    }

    public String getTargetDownloadDirectory() {
        return prop.getProperty("target_download_directory");
    }

    public Integer getClientTaskFetchDelay() {
        if (clientFetchDelay == null) {
            clientFetchDelay = Integer.valueOf(prop.getProperty("client_fetch_delay")) * 1000;
        }
        assert (clientFetchDelay != null);
        return clientFetchDelay;
    }
}
